public class MinModifyDistance {
}
class MinModifyDistanceSolution {
    public int minDistance(String word1, String word2) {
        char[] chas1 = word1.toCharArray();
        char[] chas2 = word2.toCharArray();
        int n1 = chas1.length;
        int n2 = chas2.length;
        int[][] dp = new int[n1+1][n2+1];
        for(int i=0;i<=n1;i++)
            dp[i][0] = i;
        for(int i=0;i<=n2;i++)
            dp[0][i] = i;
        for(int i=1;i<=n1;i++){
            for(int j=1;j<=n2;j++){
                int loru = Math.min(dp[i-1][j],dp[i][j-1])+1;
                int landu = chas1[i-1]==chas2[j-1]?dp[i-1][j-1]:dp[i-1][j-1]+1;
                dp[i][j] = Math.min(loru,landu);
            }
        }
        return dp[n1][n2];
    }
}
